package com.yinhai.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.androidquery.AQuery;
import com.yinhai.activity.R;

public class MSGListAdapter extends BaseAdapter {
	/**
	 * 上下文对象
	 */
	private List<Map<String, Object>> data;

	Context  mContext=null;
	 
	private AQuery aq = null;
	public MSGListAdapter(Context ctx ,List<Map<String, Object>> dataList) {
		this.mContext = ctx;
		this.data = dataList;
	}

	@Override
	public int getCount() {
		return this.data.size();
	}
	
	public void addMap(Map<String, Object> map){
	    this.data.add(map);
	}
	
	public void delMap(Map<String, Object> valMap){
	    this.data.remove(valMap);
	}

	@Override
	public  Map<String, Object> getItem(int position) {
		return this.data.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
	//	ViewHolder holder;
		if (convertView == null) {
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.msg_sms_list_item, null);
		/*	holder = new ViewHolder();
			holder.item_left = (RelativeLayout) convertView
					.findViewById(R.id.item_left);
			holder.item_right = (RelativeLayout) convertView
					.findViewById(R.id.item_right);

			holder.msg_name = (TextView) convertView.findViewById(R.id.msg_name);
			holder.msg_content = (TextView) convertView.findViewById(R.id.msg_content);
			//holder.item_right_txt = (TextView) convertView.findViewById(R.id.item_right_txt);
			holder.number= (TextView)convertView.findViewById(R.id.number);
			holder.msg_date = (TextView)convertView.findViewById(R.id.msg_date);
			//holder.img = (ImageView)convertView.findViewById(R.id.img);
			convertView.setTag(holder);*/
			
		} /*else {// 有直接获得ViewHolder
			holder = (ViewHolder) convertView.getTag();
		}*/
		
		aq = new AQuery(convertView);
		aq.id(R.id.msg_name).text(this.data.get(position).get("name")+"");
		aq.id(R.id.msg_content).text(this.data.get(position).get("content")+"");
		aq.id(R.id.msg_date).text(this.data.get(position).get("date")+"").visible();
		aq.id(R.id.img).tag(this.data.get(position));
//		.clicked(new OnClickListener() {
//            @Override
//            public void onClick(View arg0) {
//                String telNo = arg0.getTag().toString();
//                if (telNo != null && telNo.length() > 0) {
//                    Uri uri = Uri.parse("tel:" + telNo);
//                    Intent intent = new Intent(Intent.ACTION_CALL, uri);
//                    mContext.startActivity(intent);
//                }
//            }
//        });
		/*    holder.msg_name.setText(data.get(position).get("name")+"");
		//holder.msg_content.setText(data.get(position).get("content")+"");
//			holder.number.setVisibility(View.GONE);
	 
			holder.msg_content.setText(data.get(position).get("content")+"");
			holder.msg_date.setText(data.get(position).get("date")+"");
			holder.msg_date.setVisibility(View.VISIBLE);*/
		

		return convertView;
	}

	/*static class ViewHolder {
		RelativeLayout item_left;
		RelativeLayout item_right;

		TextView msg_name;
		TextView msg_content;
		TextView number;
	//	TextView item_right_txt;
		TextView msg_date;
		ImageView img;
	}*/
	 
}
